require "tcl"

module TclBot
  class Interp < Tcl::SafeInterp
    attr_accessor :delegate
    
    def initialize
      super
      @unsafe_interp = Tcl::Interp.new
      expose :clock
    end
    
    def tcl_clock(*args)
      @unsafe_interp._!(:clock, *args)
    end
    
    def interp_receive(method, *args)
      super
    rescue NoMethodError => e
      raise unless delegate
      delegate.send("tcl_#{method}", *args)
    end
    
    def eval_and_truncate(script, limit)
      eval(script)[0, limit]
    end
  end
end
